package cn.edu.zafu.bigdata.Wym;

public class Wym_getElement {

    public static void main(String[] args){
        int[] arr={1,2,3,4,5,6,7};
        int index=8;

        try{
            int element= getelement(arr,index);
            System.out.println("数组中的索引"+index+"的元素是："+element);
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("错误："+e.getMessage());
        }
    }

    public static int getelement(int[] arr, int index){
        if(index<0||index>=arr.length){
            throw new ArrayIndexOutOfBoundsException("提供的索引"+index+"超出数组范围");
        }
        return arr[index];
    }

}
